#ifndef MOPPLINK_H
#define MOPPLINK_H

#include <stdio.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#include <string.h>
#include <errno.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>

#include <openssl/des.h>

#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/bio.h>

#include <openssl/md5.h>

#include <time.h>

#include "crypt.h"

#include "queue.h"

#include "cJSON.h"

typedef struct MopplinkCore {
    char *ip;
    int port;
    int heartBeatTime;
    int timeout;
    char *keyPath;
    char isGM;
    Encrypt (*asymmetricEncryption)(char *data, char *key_path);
    Encrypt (*symmetricEncryption)(char *desPassword, char *data, int length);
    Encrypt (*symmetricDecryption)(char *desPassword, char *data, int length);
    char *(*digest)(char *data, int length);
    void (*onError)(int errorCode, char *errorData);
    void (*onMsgArrived)(int sq, char *data);
    void (*onTimeout)(int sq);
} MopplinkCore;

typedef struct RequestPackage {
    int app;
    char *service;
    char *action;
    char *body;
    char *user;
    char *session;
} RequestPackage;

int moppStart(MopplinkCore mopplinkCore);
int coreSend(char *waitSendData, int dataLength);
int moppSend(RequestPackage requestPackage);

#endif